/**
 * This file is part of the educational usermanagement system.
 * 
 * Copyright (c) 2008, Florian Arndt, Thomas Kemptner, Christian Kerl, Patrick Neuberger, Marcel Rehfeld, Emal Sadran, Stefan Sauer
 * 
 * Released under the MIT License http://www.opensource.org/licenses/mit-license.php
 */

package edu.ba.management.data.search.comparer;

import java.util.regex.*;

/**
 * The StringEqualityComparer is the implementation of the IEqualityComparer
 * interface for the java.lang.String class. It uses regular expressions for
 * comparison.
 */
public class StringEqualityComparer implements IEqualityComparer
{
    /*
     * (non-Javadoc)
     * 
     * @see edu.ba.management.data.search.comparer.IEqualityComparer#compare(java.lang.Object,
     *      java.lang.Object)
     */
    @Override
    public boolean compare(Object value, Object reference_value)
    {
        if (value.getClass().equals(String.class)
                && reference_value.getClass().equals(String.class))
        {
            String str1 = (String) value;
            String str2 = (String) reference_value;

            Matcher matcher = Pattern.compile(str2).matcher(str1);

            return matcher.matches();
        }

        return false;
    }
}
